<template>
    <h2>会员权益修改页面</h2>
    <table border="1">
        <tr>
            <td>权益名称</td>
            <td>
                <input type="text" v-model="rightback.MR_Name"/>
            </td>
        </tr>
        <tr>
            <td>权益说明</td>
            <td>
                <textarea rows="3" v-model="rightback.MR_Info"></textarea>
            </td>
        </tr>
        <tr>
            <td>权益是否自定义</td>
            <td>
                <input type="radio" name="isCustom" value="true" v-model="rightback.MR_IsCustom" />是
                <input type="radio" name="isCustom" value="false" v-model="rightback.MR_IsCustom" />否
            </td>
        </tr>
        <tr>
            <td>权益类型</td>
            <td>
                <select v-model="rightback.MR_RuleType">
                    <option value="0">请选择</option>
                    <option value="1">折扣</option>
                    <option value="2">餐饮（附赠早餐，午餐，晚餐）</option>
                    <option value="3">延时</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>权益规则</td>
            <td>
                <input type="text" v-model="rightback.MR_Rule"/>
            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <input type="button" value="修改权益" class="btn btn-success" @click="upRight" />
            </td>
        </tr>
    </table>
</template>

<script setup lang="ts">
  import {onMounted,reactive} from 'vue'//reactive创建响应式对象
    import {useRoute,useRouter} from 'vue-router'
    import axios from 'axios'
    const route=useRoute();
    const router=useRouter();
    const rightback=reactive({
        "MR_Id": 1,
      "MR_Name": "",
      "MR_Info": "",
      "MR_IsCustom": true,
      "MR_RuleType": 2,
      "MR_Rule": ""
    })

    onMounted(()=>{
        axios.get('https://localhost:44320/api/Member/RightBack',{
            params:{
                MRId:route.params.mRid
            }
        })
        .then(res=>{
            console.log(res.data);
            rightback.MR_Name=res.data.MR_Name;
            rightback.MR_Info=res.data.MR_Info;
            rightback.MR_IsCustom=res.data.MR_IsCustom;
            rightback.MR_RuleType=res.data.MR_RuleType;
            rightback.MR_Rule=res.data.MR_Rule;
        })
    })

    const upRight=()=>{
        axios.put('https://localhost:7120/api/Member/RightEdit',{
  "mR_Id":route.params.mRid,
  "mR_Name": rightback.MR_Name,
  "mR_Info": rightback.MR_Info,
  "mR_IsCustom": rightback.MR_IsCustom,
  "mR_RuleType": rightback.MR_RuleType,
  "mR_Rule": rightback.MR_Rule
        })
        .then(res=>{
            console.log(res.data);
            if(res.data>0)
            {
                alert('修改成功');
                router.push('/showRight');
            }
            else{alert('修改失败');}
        })
        .catch(error=>{
            console.log(error);
        })
    }

</script>